import { useTable, LIST_TYPE } from '@crud/index';
import { getClueList as getList } from '@/api/crm-kgj/sales';
import { formatParamsSelectVal } from '@/utils';

/** 线索类型 */
export const clueTypeOptions = [
  { label: '不限', value: -1 },
  { label: '过期会员', value: 0 },
  { label: '活跃新用户', value: 1 }
];
/** 成交意向 */
export const purposeOptions = [
  { label: '不限', value: -1 },
  { label: '未跟进', value: 4 },
  { label: '未建联', value: 0 },
  { label: '不明确', value: 1 },
  { label: '有意向', value: 2 },
  { label: '无意向', value: 3 }
];
/** 跟踪状态类型 */
export const trackStateOptions = [
  { label: '不限', value: -1 },
  { label: '跟踪中', value: 0 },
  { label: '跟踪完成', value: 1 },
  { label: '跟踪到期', value: 2 }
];
/** 添加类型 */
export const addTypeOptions = [
  { label: '不限', value: -1 },
  { label: '已添加', value: 1 },
  { label: '未添加', value: 0 }
];
/** 公司规模 */
export const companySizeOptions = [
  { label: '不限', value: -1 },
  { label: '10人以下', value: 1 },
  { label: '10-50人', value: 2 },
  { label: '50人以上', value: 3 }
];
/** 线索中公司规模 */
export const ClueCompanySizeOptions = [
  { label: '未知', value: 0 },
  { label: '10人以下', value: 1 },
  { label: '10-50人', value: 2 },
  { label: '50人以上', value: 3 }
];

/** 设备枚举 */
export const platformOptions = [
  { label: 'PC', value: 1 },
  { label: '安卓App', value: 2 },
  { label: '苹果App', value: 3 },
  { label: '小程序', value: 4 }
];
export const statusColorMap = {
  跟踪中: 0,
  跟踪完成: 1,
  跟踪到期: 2
};
export const useTableList = (options: any = {}) => {
  const columns = [
    {
      label: '手机号',
      prop: 'mobile',
      align: 'center',
      width: 140,
      render: 'mobile'
    },
    {
      label: '线索类型',
      prop: 'sales_user_type',
      align: 'center',
      width: 122
    },
    {
      label: '倒计时',
      prop: 'sales_end_time',
      align: 'center',
      render: 'sales_end_time',
      sortable: 'custom',
      minWidth: 190
    },
    {
      label: '状态',
      prop: 'clue_follow_type',
      render: 'clue_follow_type',
      align: 'center',
      width: 100
    },
    {
      label: '成交意向',
      prop: 'deal_intent',
      align: 'center',
      width: 100
    },
    {
      label: '企业微信',
      prop: 'enterprise_wechat',
      align: 'center',
      width: 100
    },
    {
      label: '公司规模',
      prop: 'company_size',
      align: 'center',
      width: 100
    },
    {
      label: '到期版本',
      prop: 'product_name',
      align: 'center',
      width: 140
    },
    {
      label: '到期时间',
      prop: 'user_end_time',
      type: 'dateTime',
      align: 'center',
      width: 177
    },
    {
      label: '跟进说明',
      prop: 'followup_notes',
      align: 'center',
      minWidth: 200
    },
    {
      label: '操作',
      align: 'center',
      render: 'actions',
      width: 160,
      fixed: 'right'
    }
  ];

  return useTable({
    ...options,
    type: LIST_TYPE.KGJ,
    params: {
      deal_intent: -1,
      clue_follow_type: -1,
      company_size: -1,
      enterprise_wechat: -1,
      sales_user_type: -1,
      sort_field: 'sales_end_time',
      sort: 1
    },
    columns,
    getParams: ({ _userTimeArr = [], _lastLoginTimeArr = [], _salesTimeArr = [], ...params }) => {
      // 处理时间参数
      if (_userTimeArr?.length) {
        const [begin, end] = _userTimeArr;
        params.user_begin_time = begin;
        params.user_end_time = end;
      }
      if (_lastLoginTimeArr?.length) {
        const [begin, end] = _lastLoginTimeArr;
        params.last_login_begin_time = begin;
        params.last_login_end_time = end;
      }
      if (_salesTimeArr?.length) {
        const [begin, end] = _salesTimeArr;
        params.sales_begin_time = begin;
        params.sales_end_time = end;
      }
      return {
        ...params,
        ...formatParamsSelectVal(
          [
            ['deal_intent', -1],
            ['clue_follow_type', -1],
            ['company_size', -1],
            ['enterprise_wechat', -1],
            ['sales_user_type', -1]
          ],
          params
        )
      };
    },
    getList
  });
};
/** 企业微信状态枚举 */
export const wechatStatus = [
  { label: '未添加', value: 0 },
  { label: '已添加', value: 1 }
];
/** 成交意向枚举 */
export const dealIntentOptions = [
  { label: '未建联', value: 0 },
  { label: '不明确', value: 1 },
  { label: '有意向', value: 2 },
  { label: '无意向', value: 3 }
];
/** 我的线索 - 用户信息 -历史订单 */
export const useHistoryTableList = (options: any = {}) => {
  const columns = [
    {
      label: '订单时间',
      prop: 'order_time',
      type: 'dateTime',
      align: 'center',
      width: 200
    },
    {
      label: '购买类型',
      prop: 'subject',
      align: 'center',
      width: 122
    },
    {
      label: '支付金额',
      prop: 'total_fee',
      align: 'center',
      width: 122
    },
    {
      label: '支付方式',
      prop: 'trade_type',
      minWidth: 100
    }
  ];

  return useTable({
    ...options,
    type: LIST_TYPE.KGJ,
    params: {},
    columns
    // getList
  });
};
/** 我的线索 - 用户信息 - 跟进历史 */
export const useFollowLogsList = (options: any = {}) => {
  const columns = [
    {
      label: '跟进时间',
      prop: 'add_time',
      type: 'dateTime',
      align: 'center',
      width: 200
    },
    {
      label: '交易意向',
      prop: 'deal_intent',
      align: 'center',
      width: 122
    },
    {
      label: '跟进说明',
      prop: 'pay_price',
      minWidth: 100
    }
  ];

  return useTable({
    ...options,
    type: LIST_TYPE.KGJ,
    params: {},
    columns
    // getList
  });
};
/** 我的线索 - 用户信息 - 销售订单 */
export const useSalesLogsList = (options: any = {}) => {
  const columns = [
    {
      label: '订单时间',
      prop: 'order_time',
      type: 'dateTime',
      align: 'center',
      width: 200
    },
    {
      label: '购买类型',
      prop: 'pay_title',
      align: 'center',
      width: 122
    },
    {
      label: '支付金额',
      prop: 'pay_price',
      width: 100
    },
    {
      label: '跟进期内',
      prop: 'is_follow_cycle',
      render: (e) => (e.is_follow_cycle ? '是' : '否'),
      align: 'center',
      minWidth: 100
    }
  ];

  return useTable({
    ...options,
    type: LIST_TYPE.KGJ,
    params: {},
    columns
    // getList
  });
};
